package org.example.mq.demo;

import org.example.mq.common.network.mqclient.Channel;
import org.example.mq.common.network.mqclient.Connection;
import org.example.mq.common.network.mqclient.ConnectionFactory;
import org.example.mq.mqserver.coreenum.ExchangeType;

import java.io.IOException;

public class DemoProducer {
    public static void main(String[] args) throws IOException, InterruptedException {
        System.out.println("启动生产者");
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("127.0.0.1");
        factory.setPort(9090);

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        //创建交换机和队列
        channel.exchangeDeclare("testExchange", ExchangeType.DIRECT,true,true,null);
        channel.queueDeclare("testQueue",true,true,true,null);

        //创建出消息
        byte[] body = "hello".getBytes();
        //发送消息
        boolean ok = channel.basicPublic("testExchange","testQueue",null,body);
        System.out.println("消息发送成功");

        Thread.sleep(500);
        channel.close();
        connection.close();
    }
}
